/*
*******************************************************************************
*                            parse_config_file
*
* Description: This function is the entry of program.
*
* Arguments  : argc         count of parameters
*
*              argv         parameters
*
*
* Returns    : == 0         Succeed.
*              <  0         Failed.
*
*
* adt_aec.conf
*
* [setting]
* bypassMode=0         ; bypass or not (0: No, 1: Yes)
* ecDump=0             ; record or not (0: No, 1: Yes)
* version=0.0.14       ; version number
*
* [GPIO]
* gpio_enable=YES      ; detect handfree signal by gpio (YES or NO)
* gpio_number=5        ; if gpio_enable=YES, you should set a number for gpio which you want to use.
*                      ; while define Macro USE_FIFO_IPC=1, this parameter will be ignore, that mean
*                      ; it will use fifo(IPC) instead of detecting gpio.
*
* [parameter]          ; if you are not sure what that means, please do not change these.
* frame_size=160       ; frame size
* max_frame_size=640   ; max frame size
* sample_rate=8000     ; sample rate
* buffer_size_ratio=8  ; receive and send buffer size ratio (must be a power of 2)
*
*******************************************************************************
*/

#include "iniparser.h"
#include "main.h"

int parse_config_file(const char *path)
{
    dictionary *ini;
    ini = iniparser_load(path);

    LOG("number:%d\n", ini->n);
    LOG("size:%ld\n", ini->size);

    g_aec.pcm_src  = PCMALSA;
    g_aec.pcm_dest = PCMALSA;
    g_aec.bypass_mode = iniparser_getint(ini, "setting:bypassmode", 0);
    strncpy(g_aec.device_name, iniparser_getstring(ini, "setting:devicename", "plughw:0,0"), 16);
#ifdef EC_DUMP
    g_aec.is_ec_dump = iniparser_getint(ini, "setting:ecdump", 0);
#endif
    g_aec.signal_src  = iniparser_getint(ini, "signal:source", 2);
    g_aec.gpio_number = iniparser_getint(ini, "signal:gpio_number", 5);

    g_aec.pcm.period_size = iniparser_getint(ini, "parameter:frame_size", 160);
    g_aec.pcm.buffer_size = iniparser_getint(ini, "parameter:max_frame_size", 640);
    g_aec.pcm.sample_rate = iniparser_getint(ini, "parameter:sample_rate", 8000);

    //iniparser_dump(ini, stdout);
    iniparser_freedict(ini);

    return 0;
}